package com.ccav.web.controller.customer;

import com.ccav.api.enmus.DictEnum;
import com.ccav.api.pojo.BaseDict;
import com.ccav.api.pojo.Customer;
import com.ccav.api.service.CustomerService;
import com.ccav.core.customer.BaseDictServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    BaseDictServiceImpl baseDictService;

    @Autowired
    CustomerService customerService;

    @GetMapping("/list")
    public String customerIndex(Integer page, Model model) {
        //初始化下拉
        List<BaseDict> customerForm = baseDictService.selectBaseDictByType(DictEnum.DictType.CustomerFrom.getValue());
        model.addAttribute("formType", customerForm);
        //查询所有用户信息
        PageHelper.startPage(page == null ? 1 : page, 5);
        List<Customer> list = customerService.pagingAll();
        PageInfo<Customer> pageInfo = new PageInfo<Customer>(list);
        model.addAttribute("customers", pageInfo);
        return "customer/customer";
    }


}
